#include "lane.h"

#define NONE "none"
#define DRIVING "driving"
#define SHOULDER "shoulder"
#define BIKING "biking"
#define SIDEWALK "sidewalk"
#define BORDER "border"
#define RESTRICKTED "restrickted"
#define PARKING "parking"
#define ENTRY "entry"
#define EXIT "exit"
#define SOLID "solid"
#define BROKEN "broken"
#define SOLIDSOLID "solid solid"
#define BROKENSOLID "broken solid"

Lane::Lane(QWidget *parent)
    : QWidget(parent)
{
    initUI();
    setLineEdit(false);
}

Lane::~Lane()
{
}

#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QGridLayout>
void Lane::initUI()
{
    QHBoxLayout *pHBLayoutPushBtn = new QHBoxLayout();
    for(int index = 0; index < 7; index++)
    {
        m_pPushBtnLane[index] = new CustomPushButton(QString::number(index - 3));
        connect(m_pPushBtnLane[index],  SIGNAL(signalClicked(QString)), this, SLOT(onPushBtnLane(QString)));
        pHBLayoutPushBtn->addWidget(m_pPushBtnLane[index]);
        pHBLayoutPushBtn->setSpacing(0);
    }

    QVBoxLayout *pVBLayoutSubsection = new QVBoxLayout();
    m_pLabel_Subsection = new QLabel("分段", this);
    m_pListWidget_SubsectionData = new QListWidget(this);
    m_pListWidget_SubsectionData->setFixedWidth(50);
    pVBLayoutSubsection->addWidget(m_pLabel_Subsection);
    pVBLayoutSubsection->addWidget(m_pListWidget_SubsectionData);

    QGridLayout *pGridLayout = new QGridLayout();
    QLabel *plabelID = new QLabel("ID:",this);
    m_pLineEdit_ID = new QLineEdit(this);
    pGridLayout->addWidget(plabelID, 0, 0, 1, 1, Qt::AlignRight);
    pGridLayout->addWidget(m_pLineEdit_ID, 0, 1);

    QLabel *plabelType = new QLabel("类型:",this);
    m_pCombox_Type = new QComboBox(this);
    QStringList strList;
    strList << NONE << DRIVING << SHOULDER << BIKING << SIDEWALK
            << BORDER << RESTRICKTED << PARKING << ENTRY << EXIT;
    m_pCombox_Type->addItems(strList);
    m_pCombox_Type->setCurrentText(DRIVING);
    pGridLayout->addWidget(plabelType, 0, 2, 1, 1, Qt::AlignRight);
    pGridLayout->addWidget(m_pCombox_Type, 0, 3);

    QLabel *plabelBaseLineOffse = new QLabel("基准线偏移:",this);
    m_pLineEdit_BaseLineOffse = new QLineEdit(this);
    pGridLayout->addWidget(plabelBaseLineOffse, 1, 0, 1, 3, Qt::AlignRight);
    pGridLayout->addWidget(m_pLineEdit_BaseLineOffse, 1, 3);

    QLabel *plabelStartPoint = new QLabel("起始点:",this);
    m_pLineEdit_StartPoint = new QLineEdit(this);
    pGridLayout->addWidget(plabelStartPoint, 2, 0, 1, 3, Qt::AlignRight);
    pGridLayout->addWidget(m_pLineEdit_StartPoint, 2, 3);

    QLabel *plabelBeforeLane = new QLabel("前接车道:",this);
    m_pLineEdit_BeforeLane = new QLineEdit(this);
    QLabel *plabelLaterLane = new QLabel("后接车道:",this);
    m_pLineEdit_LaterLane = new QLineEdit(this);
    pGridLayout->addWidget(plabelBeforeLane, 3, 0, 1, 1, Qt::AlignRight);
    pGridLayout->addWidget(m_pLineEdit_BeforeLane, 3, 1);
    pGridLayout->addWidget(plabelLaterLane, 3, 2, 1, 1, Qt::AlignRight);
    pGridLayout->addWidget(m_pLineEdit_LaterLane, 3, 3);

    QLabel *plabelLaneWidth = new QLabel("车道宽度:",this);
    m_pLineEdit_LaneWidth = new QLineEdit(this);
    m_pLineEdit_LaneWidth->setText("3.5米");
    QLabel *plabelLaneSpeed = new QLabel("车道速度:",this);
    m_pLineEdit_LaneSpeed = new QLineEdit(this);
    m_pLineEdit_LaneSpeed->setText("60km/h");
    pGridLayout->addWidget(plabelLaneWidth, 4, 0, 1, 1, Qt::AlignRight);
    pGridLayout->addWidget(m_pLineEdit_LaneWidth, 4, 1);
    pGridLayout->addWidget(plabelLaneSpeed, 4, 2, 1, 1, Qt::AlignRight);
    pGridLayout->addWidget(m_pLineEdit_LaneSpeed, 4, 3);

    QLabel *plabelSideBoundary = new QLabel("边线", this);
    pGridLayout->addWidget(plabelSideBoundary, 5, 0, 1, 1, Qt::AlignLeft);

    QLabel *plabelSideBoundary_Start = new QLabel("起始:",this);
    m_pLineEdit_SideBoundary_Start = new QLineEdit(this);
    pGridLayout->addWidget(plabelSideBoundary_Start, 6, 0, 1, 1, Qt::AlignRight);
    pGridLayout->addWidget(m_pLineEdit_SideBoundary_Start, 6, 1);

    QLabel *plabelSideBoundaryType = new QLabel("类型:",this);
    m_pCombox_SideBoundary_Type = new QComboBox(this);
    QStringList strListSideBoundary;
    strListSideBoundary << NONE << SOLID << BROKEN << SOLIDSOLID << BROKENSOLID;
    m_pCombox_SideBoundary_Type->addItems(strListSideBoundary);
    m_pCombox_SideBoundary_Type->setCurrentText(NONE);
    pGridLayout->addWidget(plabelSideBoundaryType, 6, 2, 1, 1, Qt::AlignRight);
    pGridLayout->addWidget(m_pCombox_SideBoundary_Type, 6, 3);

    QLabel *plabelSideBoundary_Color = new QLabel("颜色:",this);
    m_pLineEdit_SideBoundary_Color = new QLineEdit(this);
    QLabel *plabelSideBoundary_Width = new QLabel("宽度:",this);
    m_pLineEdit_SideBoundary_Width = new QLineEdit(this);
    pGridLayout->addWidget(plabelSideBoundary_Color, 7, 0, 1, 1, Qt::AlignRight);
    pGridLayout->addWidget(m_pLineEdit_SideBoundary_Color, 7, 1);
    pGridLayout->addWidget(plabelSideBoundary_Width, 7, 2, 1, 1, Qt::AlignRight);
    pGridLayout->addWidget(m_pLineEdit_SideBoundary_Width, 7, 3);

    QLabel *plabelSideBoundary_LaneChange = new QLabel("车道改变:",this);
    m_pLineEdit_SideBoundary_LaneChange = new QLineEdit(this);
    QLabel *plabelSideBoundary_Higth = new QLabel("高度:",this);
    m_pLineEdit_SideBoundary_Higth = new QLineEdit(this);
    pGridLayout->addWidget(plabelSideBoundary_LaneChange, 8, 0, 1, 1, Qt::AlignRight);
    pGridLayout->addWidget(m_pLineEdit_SideBoundary_LaneChange, 8, 1);
    pGridLayout->addWidget(plabelSideBoundary_Higth, 8, 2, 1, 1, Qt::AlignRight);
    pGridLayout->addWidget(m_pLineEdit_SideBoundary_Higth, 8, 3);

    QHBoxLayout *pHBLayout = new QHBoxLayout();
    pHBLayout->addLayout(pVBLayoutSubsection);
    pHBLayout->addLayout(pGridLayout);
//    HBLayout->setStretchFactor(VBLayoutSubsection, 1);
//    HBLayout->setStretchFactor(GridLayout, 9);


    QVBoxLayout *pVBLayout = new QVBoxLayout();
    pVBLayout->addLayout(pHBLayoutPushBtn);
    pVBLayout->addLayout(pHBLayout);

    setLayout(pVBLayout);
}

void Lane::initSignalSlot()
{
    connect(this, SIGNAL(signalPushBtnClicked(int)), this, SLOT(onPushBtnLane(int)));
}


void Lane::setLineEdit(bool bState)
{
    m_pLineEdit_ID->setEnabled(bState);
    m_pLineEdit_BaseLineOffse->setEnabled(bState);
    m_pLineEdit_StartPoint->setEnabled(bState);
    m_pLineEdit_BeforeLane->setEnabled(bState);
    m_pLineEdit_LaterLane->setEnabled(bState);
    m_pLineEdit_LaneWidth->setEnabled(bState);
    m_pLineEdit_LaneSpeed->setEnabled(bState);

    m_pLineEdit_SideBoundary_Start->setEnabled(bState);
    m_pLineEdit_SideBoundary_Color->setEnabled(bState);
    m_pLineEdit_SideBoundary_Width->setEnabled(bState);
    m_pLineEdit_SideBoundary_LaneChange->setEnabled(bState);
    m_pLineEdit_SideBoundary_Higth->setEnabled(bState);
}

#include <QDebug>
void Lane::onPushBtnLane(QString strName)
{
    qDebug() << strName;
}
